<?php
class User_model extends CI_Model{
    private $_tab = 'user';
    function  __construct(){
        parent::__construct();
    }
    // Lay thong tin cua userid
    function getInfo($userid){
        $this->db->where('userid',$userid );
        $query = $this->db->get($this->_tab);
        if($query) return $query->row_array();
        else return false;
    }
    // Kiem tra du lieu ve username va password co ton tai khong
    function checkUser($username,$password){
        $this->db->where('username',$username);
        $this->db->where('password',$password);
        
        $query = $this->db->get($this->_tab);
        if($query->num_rows() == 0) return false;
        else return $query->row_array();
    }
    // Lay tat ca du lieu trong bang user
    function getAll($off = '',$limit = ''){
        $this->db->limit($off,$limit);
        $this->db->order_by('userid','asc'); // 'asc' la tang dan ,'desc' là giam dan, 'random'...
        
        $query = $this->db->get($this->_tab);
        $data = $query->result_array();
        return $data;
    }
    // Tong so record co trong du lieu
    function numRows(){
        return $this->db->count_all($this->_tab);
    }
    // Xoa user trong tab
    function deleteUser($userid){
        $this->db->where('userid',$userid);
        $this->db->delete($this->_tab);
    }
}